<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>重置密码</title>
    <link rel="stylesheet" type="text/css" href="__CSS__/login_register.css">
</head>
<body>
<div class="topbar-between horizontal-view gradient-color">
    <div class="topbar-back" onclick="location.href='/Wx/Login/userInfo'"><div class="topbar-back-icon"></div></div>
    <div class="topbar-title">重置密码</div>
    <div class="topbar-right"></div>
</div>
<div class="input-margin">
    <input id="phone" class="input-border" type="tel" maxlength="11" name="register_name" placeholder="手机号码"/>
</div>
<div class="auth-wrap horizontal-view">
    <input id="secCode" class="input-border-auth" type="text" maxlength="" name="register_auth" placeholder="请输入手机验证码"/>
    <div id="yanzhenma" class="auth-button" style="align-self: flex-end;margin-bottom: 3px;" onclick="getCode()" >获取验证码</div>
</div>
<div class="input-margin">
    <input id="pwd" class="input-border" type="password" name="register_pwd" placeholder="请重新设置密码" />
</div>
<div class="button-simple gradient-color" onclick="resetPwd()">确定</div>
<input type="hidden" name="isrepeat" id="isrepeat" value="0" />
<input type="hidden" name="sendStatus" id="sendStatus" value="0" />
<script src="__JS__/jquery2.1.1.min.js"></script>
<script src="__JS__/layer.min.js"></script>
<script>
//60秒倒计时
var countdown = 120;
function settime(val) {
    if(val==0){
        countdown=0;
        return;
    }
    if (countdown == 0) {
        $('#sendStatus').val(0);
        $('#yanzhenma').text('获取验证码');
        countdown = 120;
        return;
    } else {
        $('#sendStatus').val(1);
        var val = "重新发送(" + countdown + ")";
        $('#yanzhenma').text(val);
        countdown--;
    }
    setTimeout(function() {
        settime(val)
    }, 1000)
}

//获取验证码
function getCode() {
    // if ($('#sendStatus').val() == 1) {
    //     layer.msg('请求过于频繁');
    //     return;
    // }
    var phone = $('#phone').val();
    var telReg = !!phone.match(/^1[3|7|4|5|8]{1}\d{9}$/);
    if (telReg == false) {
        layer.msg('手机格式不正确');
        return;
    }
    settime();
    $.ajax({
        type : "POST",
        url : "/Wx/Login/getCode",
        data : {
            phone : phone,
            type : 2
        },
        dataType : "json",
        success : function(data) {
            try {
                if (data.status == -2) {
                    settime(0);
                    layer.msg('操作过于频繁');
                    return;
                }else if(data.status==-5){
                    layer.msg('手机号不存在');
                    return;
                }
            } catch (err) {

            }
        }
    });
}

function resetPwd() {
    if($('#isrepeat').val()==1){
        layer.msg('请勿重复提交');
        return;
    }
    var phone = $('#phone').val();
    var secCode = $('#secCode').val();
    var telReg = !!phone.match(/^1[3|7|4|5|8]{1}\d{9}$/);
    var pwd = $.trim($('#pwd').val());
    if (telReg == false) {
        layer.msg('手机格式不正确');
        return;
    }
    if (secCode.length != 6) {
        layer.msg('请输入6位验证码');
        return;
    }
    if (pwd.length < 6 ) {
        layer.msg('请输入6位以上密码');
        return;
    }
    $('#isrepeat').val(1);
    $.ajax({
        type : "POST",
        url : "/Wx/Login/resetLoginPwdHandle",
        data : {
            phone : phone,
            pwd : pwd,
            code:secCode
        },
        dataType : "json",
        success : function(data) {
            try {
                if (data.status == -1) {
                    $('#isrepeat').val(0);
                    layer.msg('手机号和密码必填');
                    return;
                } else if (data.status == -3) {
                    $('#isrepeat').val(0);
                    layer.msg('验证码错误');
                    return;
                } else if (data.status == -2) {
                    $('#isrepeat').val(0);
                    layer.msg('手机号不存在');
                    return;
                } else if (data.status == -4) {
                    $('#isrepeat').val(0);
                    layer.msg('重置密码失败');
                    return;
                } else if (data.status == 0) {
                    $('#isrepeat').val(1);
                    layer.msg('密码已重置');
                    setTimeout(function(){
                        location.href="/Wx/Login/Login";
                    },2000);
                    return;
                }

            } catch (err) {

            }
            console.log(data);
        }
    });

}
</script>
</body>
</html>